﻿using System;
using System.Web;
using System.Web.SessionState;
using System.Collections.Generic;
using System.Data;
using System.Web.Security;
using Gift.DAL;
using Gift.Model;

using Gift.Utile;
using Gift.WebApp;

namespace WebApp.cn.ashx
{
    public class isAddToAccountHandler : IHttpHandler, IRequiresSessionState
    {
      
       
        tbCar oCar;
        /// <summary>
        /// 您将需要在您网站的 web.config 文件中配置此处理程序，
        /// 并向 IIS 注册此处理程序，然后才能进行使用。有关详细信息，
        /// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // 如果无法为其他请求重用托管处理程序，则返回 false。
            // 如果按请求保留某些状态信息，则通常这将为 false。
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            BasePage thePage = new BasePage();
            if (thePage.LoginUserMember == null)
            {
                context.Response.Write("1002");
                return;
            }

            tbGoods oGoods;
            oGoods = BaseFactory.theGoods.GetModel(int.Parse(re.replace(context.Request["pid"])));


            tbCardType oCardType = new tbCardType();
            DALCardType theCardType = new DALCardType();

            string sPid = context.Request["pid"];
            string sPrice = context.Request["price"]; 
            string sProNum = context.Request["pronum"];

            string sProfessionAreaName = string.Empty;

            if (oGoods.isProfShelves == true)
            {
                if (thePage.LoginUserMember.DicUserCardList == null || thePage.LoginUserMember.DicUserCardList.Count <= 0)
                {
                    context.Response.Write("1002");
                    return;
                }
                sProfessionAreaName = EnumProfessionPriceType.Profession.ToString();
               
            
            }
            else
            {
                sProfessionAreaName = EnumProfessionPriceType.Shopping.ToString();
            }


            if (thePage.LoginUserMember != null)
            {
                try
                {
                    re.WriteCookie("tempno", thePage.LoginUserMember.MemberId, 30);
                }
                catch { }
            }
            string str3 = "0";
            string str4 = "";
            string str5 = "0";
            str3 = context.Request["price"];
            str4 = context.Request["content"]; 
            str5 = context.Request["pronum"];

            oCar = new tbCar();
            oCar.ProductId = int.Parse(sPid);
            oCar.orderId = 0;
            oCar.ProdNumber = int.Parse(str5);
            oCar.Contents = str4;
            oCar.ProdPrice = decimal.Parse(str3);
            oCar.UpdateDate = DateTime.Now;
            BaseFactory.theCar.Add(oCar);

        }

        #endregion
    }
}
